const crypto = require('crypto');
function encrypted(text, secret) {
    // 创建 Hmac 加密器，指定算法为 MD5，并提供密钥
    const hmac = crypto.createHmac('md5', secret);

    // 更新加密器的内容
    hmac.update(text);
    return hmac.digest('hex');
}

function encryptAES(text, key) {
    const cipher = crypto.createCipher('aes-256-cbc', key);
    let encrypted = cipher.update(text, 'utf8', 'hex');
    encrypted += cipher.final('hex');
    return encrypted;
}

function decryptAES(encryptedText, key) {
    const decipher = crypto.createDecipher('aes-256-cbc', key);
    let decrypted = decipher.update(encryptedText, 'hex', 'utf8');
    decrypted += decipher.final('utf8');
    return decrypted;
}

module.exports = {
    encrypted,
    encryptAES,
    decryptAES
}